import 'package:core/extension/extension_color.dart';
import 'package:core/extension/extension_num.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';

class InputWidget extends StatefulWidget {
  final TextEditingController? controller;
  final String? hint;
  final TextInputType? inputType;
  final TextAlign? textAlign;
  final TextStyle? textStyle;
  final FocusNode? focusNode;
  final bool autofocus;
  final int? maxLength;
  final int? maxLines;
  final List<TextInputFormatter>? inputFormatters;
  final ValueChanged<String>? onChanged;
  final ValueChanged<String>? onSubmitted;

  const InputWidget({
    super.key,
    this.controller,
    this.hint,
    this.inputType,
    this.textAlign,
    this.textStyle,
    this.focusNode,
    this.autofocus = false,
    this.maxLength,
    this.maxLines,
    this.inputFormatters,
    this.onChanged,
    this.onSubmitted,
  });

  @override
  State<InputWidget> createState() => _InputWidgetState();
}

class _InputWidgetState extends State<InputWidget> {
  @override
  Widget build(BuildContext context) {
    return TextField(
      controller: widget.controller,
      style: widget.textStyle,
      keyboardType: widget.inputType,
      textAlign: widget.textAlign ?? TextAlign.start,
      focusNode: widget.focusNode,
      autofocus: widget.autofocus,
      inputFormatters: widget.inputFormatters,
      maxLength: widget.maxLength,
      maxLines: widget.maxLines,
      scrollPadding: EdgeInsets.zero,
      decoration: InputDecoration(
        hintText: widget.hint,
        hintMaxLines: 1,
        hintStyle: const Color(0xFF999999).toStyle(28.px),
        contentPadding: EdgeInsets.zero,
        isDense: true,
        focusedBorder: const OutlineInputBorder(borderSide: BorderSide(width: 0, color: Colors.transparent)),
        disabledBorder: const OutlineInputBorder(borderSide: BorderSide(width: 0, color: Colors.transparent)),
        enabledBorder: const OutlineInputBorder(borderSide: BorderSide(width: 0, color: Colors.transparent)),
        border: const OutlineInputBorder(borderSide: BorderSide(width: 0, color: Colors.transparent)),
      ),
      onChanged: widget.onChanged,
      onSubmitted: widget.onSubmitted,
    );
  }
}
